package cn.justweb;

import java.util.ArrayList;
import java.util.Scanner;

/*
* ​	创建一个存储学生对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合

​        学生的姓名和年龄来自于键盘录入
*
* */
public class Demo4 {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        //
        for (int i = 0; i<3; i++) {
            addStudent(list);
        }
        for (int i = 0; i < list.size(); i++) {
            Student student=list.get(i);
            System.out.println(student);
        }

    }

    private static void addStudent(ArrayList<Student> list) {
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入学生姓名");
        String name = sc.nextLine();
        System.out.println("请输入学生年龄");
        String age = sc.nextLine();
        Student student =new Student(name,age);
        list.add(student);

    }

}
